﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gnome.Entities;
using Microsoft.Xna.Framework;
using FlatRedBall;

namespace Gnome.Engine
{
    class PowerUpFactory
    {
        //This list stores each available powerup and its probability of spawning as a key-value pair.
        //A list is used to store this to ensure probablility is properly maintained when calculating which
        //powerup to spawn.
        private static readonly List<Dictionary<PowerUp.VariableState, int>> probabilities = new List<Dictionary<PowerUp.VariableState, int>>
        {
            {new Dictionary<PowerUp.VariableState, int> {{PowerUp.VariableState.SpeedUp, 100}}}
        };

        /*
         * This method is called when a new item is needed. The method chooses an item type
         * at random. Then, based on the chosen type, it sets the object's state, weight, and value
         */
        public static PowerUp get(Vector3 position, String contentManagerName)
        {
            //Select object type at random.
            int value = FlatRedBallServices.Random.Next(1, 101);
            int probability = 0;
            PowerUp.VariableState type = PowerUp.VariableState.Normal;
            foreach (Dictionary<PowerUp.VariableState, int> pup in probabilities)
            {
                probability += pup.Values.ElementAt(0);
                if (value <= probability)
                {
                    type = pup.Keys.ElementAt(0);
                    break;
                }
            }
            //Make a new item based on the given type
            PowerUp returnpup = new PowerUp(contentManagerName);
            returnpup.CurrentState = type;
            returnpup.Position = position;
            returnpup.CollisionBox.Position = position;
            //returnpup.ItemSpriteScaleX = resizeFactor;
            //returnItem.ItemSpriteScaleY = resizeFactor;
            //returnItem.CollisionBox.ScaleX = resizeFactor;
            //returnItem.CollisionBox.ScaleY = resizeFactor;
            return returnpup;
        }
    }
}
